using System.CodeDom;
using CodeDomHelper.Types;
using System;
using System.Diagnostics;

namespace CodeDomHelper.CodeDom
{

    [DebuggerDisplay("{methodName}", Name = "MethodExp")]
    [Serializable()]
    [System.Diagnostics.DebuggerStepThrough()]
    public partial class MethodExp : CodeMethodReferenceExpression, IType
    {

        #region Ctor

        public MethodExp(System.CodeDom.CodeExpression targetObject, System.String methodName)
            : base(targetObject, methodName)
        {
            
        }
        public MethodExp(System.CodeDom.CodeExpression targetObject, string methodName, System.CodeDom.CodeTypeReference[] typeParameters)
            : base(targetObject, methodName, typeParameters)
        {
            
        }        
        

        public MethodExp(System.CodeDom.CodeExpression targetObject, string methodName, string returnTypeName)
            : base(targetObject, methodName)
        {
            Type = new TypeExp(returnTypeName);
        }        
        public MethodExp(System.CodeDom.CodeExpression targetObject, string methodName, string returnTypeName, System.CodeDom.CodeTypeReference[] typeParameters)
            : base(targetObject, methodName, typeParameters)
        {
            Type = new TypeExp(returnTypeName);
        }


        public MethodExp(System.CodeDom.CodeExpression targetObject, string methodName, Type returnType)
            : base(targetObject, methodName)
        {
            if (returnType != null)
                Type = new TypeExp(returnType);
        }

        public MethodExp(System.CodeDom.CodeExpression targetObject, string methodName, Type returnType, System.CodeDom.CodeTypeReference[] typeParameters)
            : base(targetObject, methodName, typeParameters)
        {
            if (returnType != null)
                Type = new TypeExp(returnType);
        }


        public MethodExp(System.CodeDom.CodeExpression targetObject, string methodName, TypeExp returnType)
            : base(targetObject, methodName)
        {
            if (returnType != null)
                Type = new TypeExp(returnType);
        }

        public MethodExp(System.CodeDom.CodeExpression targetObject, string methodName, TypeExp returnType, System.CodeDom.CodeTypeReference[] typeParameters)
            : base(targetObject, methodName, typeParameters)
        {
            if (returnType != null)
                Type = new TypeExp(returnType);
        }


        public MethodExp(System.CodeDom.CodeExpression targetObject, string methodName, TypeExpression returnType)
            : base(targetObject, methodName)
        {
            Type = new TypeExp(returnType);
        }
        public MethodExp(System.CodeDom.CodeExpression targetObject, string methodName, TypeExpression returnType, System.CodeDom.CodeTypeReference[] typeParameters)
            : base(targetObject, methodName, typeParameters)
        {
            Type = new TypeExp(returnType);
        }

        #endregion

        public TypeExp Type { get; private set; }

        public MethodInvoke Call(params CodeExpression[] parameters)
        {

            if (Type != null)
                return new MethodInvoke(this, Type, parameters);
         
            return new MethodInvoke(this, parameters);

        }

    }

}
